import subprocess
def evaluate_code(student_code,test_input_all):
    try:
        # 将学生代码写入文件
        with open("student_code.py", "w") as file:
            file.write(student_code)
        test_input=test_input_all[0]
        print(test_input)
        # 将测试用例写入文件
        with open("test_input.txt", "w") as file:
            file.write(test_input)

        # 尝试运行学生代码，并将测试用例作为输入
        result = subprocess.run(["python", "student_code.py"], capture_output=True, text=True, input=test_input)

        # 检查是否有编译错误
        if result.returncode != 0:
            return False, f"编译错误：\n{result.stderr}"

        student_output = result.stdout.strip()  # 学生代码的输出
        print(student_output)
        # 执行正确的代码，并将测试用例作为输入
        correct_output = test_input_all[1]  # 正确代码的输出

        # 比较学生输出和正确输出
        if student_output == correct_output:
            return True, "答案正确！"
        else:
            return False, "答案不正确。"
    except Exception as e:
        return False, f"运行时错误：{e}"


def oo(student_code, test_input):
    result, message = evaluate_code(student_code, test_input)
    return [result, message]
if __name__ == '__main__':
    student_code = """
num = int(input())
print(num * 2)
    """
    test_input = ["5", "10"]
    print(oo(student_code,test_input))